package com.greencloud.mapstruct.convert;

import com.greencloud.mapstruct.dto.UserDto;
import com.greencloud.mapstruct.entity.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author LiuDehuai
 * @fileName:UserConverter
 * @Date:2025/2/5 上午9:54
 */
@Mapper
public interface UserConverter {
    UserConverter INSTANCE = Mappers.getMapper(UserConverter.class);

    /**
     * DTO -> PO
     *
     * @param userDto
     * @return
     */
    // 指定日期属性的转换格式
    @Mapping(target = "dateOfBirth", source = "dateOfBirth", dateFormat = "yyyy-MM-dd HH:mm:ss")
    User dto2Po(UserDto userDto);

    // 指定日期属性的转换格式
    @Mapping(target = "dateOfBirth", source = "dateOfBirth", dateFormat = "yyyy-MM-dd HH:mm:ss")
    List<User> dtoList2PoList(List<UserDto> userDtoList);

    /**
     * PO -> DTO
     *
     * @param user
     * @return
     */
    // 指定日期属性的转换格式
    @Mapping(target = "dateOfBirth", source = "dateOfBirth", dateFormat = "yyyy-MM-dd HH:mm:ss")
    UserDto po2Dto(User user);

    @Mapping(target = "dateOfBirth", source = "dateOfBirth", dateFormat = "yyyy-MM-dd HH:mm:ss")
    List<UserDto> poList2DtoList(List<User> userList);
}
